import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';

const { createConfirm } = useMessage();

enum Api {
  list = '/nurse_nurses/nurseNurses/list',
  listAll = '/nurse_nurses/nurseNurses/listAll',
  save = '/nurse_nurses/nurseNurses/add',
  edit = '/nurse_nurses/nurseNurses/edit',
  deleteOne = '/nurse_nurses/nurseNurses/delete',
  deleteBatch = '/nurse_nurses/nurseNurses/deleteBatch',
  importExcel = '/nurse_nurses/nurseNurses/importExcel',
  exportXls = '/nurse_nurses/nurseNurses/exportXls',
  nurseNursesCertificateList = '/nurse_nurses/nurseNurses/listNurseNursesCertificateByMainId',
  nurseNursesCertificateSave = '/nurse_nurses/nurseNurses/addNurseNursesCertificate',
  nurseNursesCertificateEdit = '/nurse_nurses/nurseNurses/editNurseNursesCertificate',
  nurseNursesCertificateDelete = '/nurse_nurses/nurseNurses/deleteNurseNursesCertificate',
  nurseNursesCertificateDeleteBatch = '/nurse_nurses/nurseNurses/deleteBatchNurseNursesCertificate',
  nurseNursesCommentList = '/nurse_nurses/nurseNurses/listNurseNursesCommentByMainId',
  nurseNursesCommentSave = '/nurse_nurses/nurseNurses/addNurseNursesComment',
  nurseNursesCommentEdit = '/nurse_nurses/nurseNurses/editNurseNursesComment',
  nurseNursesCommentDelete = '/nurse_nurses/nurseNurses/deleteNurseNursesComment',
  nurseNursesCommentDeleteBatch = '/nurse_nurses/nurseNurses/deleteBatchNurseNursesComment',
  setOpenid = '/nurse_nurses/nurseNurses/setOpenid',
  getDepartName = '/sys/sysDepart/getDepartName',
  queryAllTreeListByPid = '/sys/sysDepart/queryAllTreeListByPid',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

export const listAll = (params) => defHttp.get({ url: Api.listAll, params });

export const listByType = (params, hasType = false) => {
  const url = hasType ? Api.list : Api.listAll;
  return defHttp.get({ url, params });
};

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};
/**
 * 列表接口
 * @param params
 */
export const nurseNursesCertificateList = (params) => {
  if (params['nursesId']) {
    return defHttp.get({ url: Api.nurseNursesCertificateList, params });
  }
  return Promise.resolve({});
};

/**
 * 删除单个
 */
export const nurseNursesCertificateDelete = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.nurseNursesCertificateDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除
 * @param params
 */
export const nurseNursesCertificateDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.nurseNursesCertificateDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 保存或者更新
 * @param params
 */
export const nurseNursesCertificateSaveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? Api.nurseNursesCertificateEdit : Api.nurseNursesCertificateSave;
  return defHttp.post({ url: url, params });
};

/**
 * 设置openid
 * @param params
 */
export const setOpenid = (params) => {
  return defHttp.get({ url: Api.setOpenid, params });
};

/**
 * 导入
 */
export const nurseNursesCertificateImportUrl = '/nurse_nurses/nurseNurses/importNurseNursesCertificate';

/**
 * 导出
 */
export const nurseNursesCertificateExportXlsUrl = '/nurse_nurses/nurseNurses/exportNurseNursesCertificate';
/**
 * 列表接口
 * @param params
 */
export const nurseNursesCommentList = (params) => {
  if (params['nursesId']) {
    return defHttp.get({ url: Api.nurseNursesCommentList, params });
  }
  return Promise.resolve({});
};

/**
 * 删除单个
 */
export const nurseNursesCommentDelete = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.nurseNursesCommentDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除
 * @param params
 */
export const nurseNursesCommentDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.nurseNursesCommentDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 保存或者更新
 * @param params
 */
export const nurseNursesCommentSaveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? Api.nurseNursesCommentEdit : Api.nurseNursesCommentSave;
  return defHttp.post({ url: url, params });
};
/**
 * 导入
 */
export const nurseNursesCommentImportUrl = '/nurse_nurses/nurseNurses/importNurseNursesComment';

/**
 * 导出
 */
export const nurseNursesCommentExportXlsUrl = '/nurse_nurses/nurseNurses/exportNurseNursesComment';

/**
 * 根据机构编码获取部门信息
 * @param params
 */
export const getDepartName = (params) => {
  return defHttp.get({ url: Api.getDepartName, params });
};

/**
 * 查询部门树形结构
 * @param params
 */
export const queryAllTreeListByPid = (params) => {
  return defHttp.get({ url: Api.queryAllTreeListByPid, params });
};
